package com.tjian.fafa.user.base.mainBody;

import android.Manifest;
import android.app.AlertDialog;
import android.app.NotificationManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.net.ConnectivityManager;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.baidu.mapapi.SDKInitializer;
import com.mikepenz.community_material_typeface_library.CommunityMaterial;
import com.mikepenz.iconics.IconicsDrawable;
import com.tjian.fafa.user.R;
import com.tjian.fafa.user.base.ConnectedApp;
import com.tjian.fafa.user.base.MainActivity_login;
import com.tjian.fafa.user.base.bean.SearchEntity;
import com.tjian.fafa.user.base.bean.UserInfo;
import com.tjian.fafa.user.base.chatServices.ChatService;
import com.tjian.fafa.user.base.chatServices.ChatServiceData;
import com.tjian.fafa.user.base.chatServices.FriendListInfo;
import com.tjian.fafa.user.base.chatServices.InitData;
import com.tjian.fafa.user.base.chatter.ChatActivity;
import com.tjian.fafa.user.base.commons.GlobalMsgTypes;
import com.tjian.fafa.user.base.friendRequest.FriendRequestService;
import com.tjian.fafa.user.base.friendRequest.FriendSearchResultActivity;
import com.tjian.fafa.user.base.myNetwork.NetStateReceiver;
import com.tjian.fafa.user.base.myNetwork.NetworkService;
import com.tjian.fafa.user.base.util.DbSaveOldMsg;
import com.tjian.fafa.user.config.PermissionConstant;
import com.tjian.fafa.user.module.courier.activity.AroundCourierActivity;
import com.tjian.fafa.user.module.courier.activity.BikeExpressageActivity;
import com.tjian.fafa.user.module.home.MainTabHomePage_only_instant_delivery_amendment;
import com.tjian.fafa.user.module.home.MainTabMyPageExtendActivity;
import com.tjian.fafa.user.util.date.DateUtilOfDemohi;

import net.oschina.app.ui.MainActivity;

import java.util.ArrayList;

import baidumapsdk.demo.RadarDemo;

import static com.baidu.location.b.g.r;
import static com.mikepenz.community_material_typeface_library.CommunityMaterial.Icon.cmd_account_multiple;
import static com.mikepenz.community_material_typeface_library.CommunityMaterial.Icon.cmd_clipboard_text;
import static com.mikepenz.community_material_typeface_library.CommunityMaterial.Icon.cmd_facebook_messenger;
import static com.tjian.fafa.user.config.PermissionConstant.READ_PHONE_STATE;

public class MainBodyActivity extends FragmentActivity
{

    private static MainBodyActivity mainBodyActivity_instance;
    private static int mCurPage;
    private static int mCurPageOnTab[];

    public static final int mPageHome = 0;
    public static final int mPageOrder = 1;
    public static final int mPageMsg = 2;
    public static final int mPageContactsList = 3;
    public static final int mPageMy = 4;

    public static final int mTabNumHome = 0;
    public static final int mTabOrder = 1;//订单
    public static final int mTabNumMsg = 2;
    public static final int mTabNumContacts = 3;
    public static final int mTabNumMy = 4;

    private CustomViewPager customViewPager;
    private ImageView tabHome_imageView;
    private ImageView tabMsgs_imageView;
    private ImageView tabContacts_imageView;
    private ImageView tabOrder_imageView;
    private ImageView tabMy_imageView;

    private LinearLayout homePageLinearLayout;
    private LinearLayout messageLinearLayout;
    private LinearLayout contactsLinearLayout;
    private LinearLayout orderLinearLayout;
    private LinearLayout mineLinearLayout;

    String mSearchedString;
    boolean mMsg9Received;

    private NetStateReceiver netStateReceiver;

    public static MainBodyActivity getInstance()
    {
        return mainBodyActivity_instance;
    }

    public static int getCurPage()
    {
        return mCurPage;
    }

    public static void setCurPage(int page)
    {
        mCurPage = page;
    }

    public static int getCurPageForTab(int tab)
    {
        return mCurPageOnTab[tab];
    }

    public static void setCurPageForTab(int tab, int page)
    {
        mCurPageOnTab[tab] = page;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);


        /*if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }*/


        setContentView(R.layout.main_body_main_container);

        mainBodyActivity_instance = this;
        mCurPage = mPageMsg;
        mCurPageOnTab = new int[5];

        mCurPageOnTab[mTabNumHome] = mPageHome;
        mCurPageOnTab[mTabOrder] = mPageOrder;//订单
        mCurPageOnTab[mTabNumMsg] = mPageMsg;
        mCurPageOnTab[mTabNumContacts] = mPageContactsList;
        mCurPageOnTab[mTabNumMy] = mPageMy;

        MainBodyService.getInstance().onInit(this);


        //启动广播接收者
        netStateReceiver = new NetStateReceiver();
        registerReceiver(netStateReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));


        customViewPager = (CustomViewPager) findViewById(R.id.main_body_main_container_tabpager);

        tabHome_imageView = (ImageView) findViewById(R.id.main_body_main_container_home);//首页
        tabHome_imageView.setImageDrawable(new IconicsDrawable(this, CommunityMaterial.Icon.cmd_home_map_marker).color(getResources().getColor(R.color.themeColor)).sizeDp(24).respectFontBounds(true));
        tabOrder_imageView = (ImageView) findViewById(R.id.main_body_main_container_friends);//订单
        tabOrder_imageView.setImageDrawable(new IconicsDrawable(this, CommunityMaterial.Icon.cmd_clipboard_text).color(getResources().getColor(R.color.main_gray)).sizeDp(24).respectFontBounds(true));
        tabMsgs_imageView = (ImageView) findViewById(R.id.main_body_main_container_msgs);//消息
        tabMsgs_imageView.setImageDrawable(new IconicsDrawable(this, CommunityMaterial.Icon.cmd_facebook_messenger).color(getResources().getColor(R.color.main_gray)).sizeDp(24).respectFontBounds(true));
        //联系人
        tabContacts_imageView = (ImageView) findViewById(R.id.main_body_main_container_contacts);
        tabContacts_imageView.setImageDrawable(new IconicsDrawable(this, CommunityMaterial.Icon.cmd_account_multiple).color(getResources().getColor(R.color.main_gray)).sizeDp(24).respectFontBounds(true));
        //个人
        tabMy_imageView = (ImageView) findViewById(R.id.main_body_main_container_my);
        tabMy_imageView.setImageDrawable(new IconicsDrawable(this, CommunityMaterial.Icon.cmd_account_circle).color(getResources().getColor(R.color.main_gray)).sizeDp(24).respectFontBounds(true));

        homePageLinearLayout = (LinearLayout) findViewById(R.id.homePageLinearLayoutId);
        homePageLinearLayout.setOnClickListener(new MainBodyOnClickListener(mTabNumHome));

        //订单
        orderLinearLayout = (LinearLayout) findViewById(R.id.findLinearLayoutId);
        orderLinearLayout.setOnClickListener(new MainBodyOnClickListener(mTabOrder));

        messageLinearLayout = (LinearLayout) findViewById(R.id.messageLinearLayoutId);
        messageLinearLayout.setOnClickListener(new MainBodyOnClickListener(mTabNumMsg));
        
        contactsLinearLayout = (LinearLayout) findViewById(R.id.contactsLinearLayoutId);
        contactsLinearLayout.setOnClickListener(new MainBodyOnClickListener(mTabNumContacts));

        mineLinearLayout = (LinearLayout) findViewById(R.id.mineLinearLayoutId);
        mineLinearLayout.setOnClickListener(new MainBodyOnClickListener(mTabNumMy));

        LayoutInflater li = LayoutInflater.from(this);

        View viewPastHome = li.inflate(R.layout.maintabhomepage_only_instant_delivery_amendment_layout, null);
        View viewPastMsgs = li.inflate(R.layout.tabmsg_main, null);

        View viewContactsList = li.inflate(R.layout.cc0_friend_list, null);
        View viewOrder = li.inflate(R.layout.main_tab_find, null);
        View viewMy = li.inflate(R.layout.tabmy_main, null);

        final ArrayList<View> listOfViews = new ArrayList<View>();
        
        listOfViews.add(viewPastHome);
        listOfViews.add(viewOrder);
        listOfViews.add(viewPastMsgs);
        listOfViews.add(viewContactsList);
        listOfViews.add(viewMy);

        PagerAdapter pagerAdapter0 = new PagerAdapter() //PagerAdapter主要是viewpager的适配器，可以实现控件的滑动效果。
        {
            @Override
            public boolean isViewFromObject(View arg0, Object arg1)
            {
                return arg0 == arg1;
            }

            @Override
            public int getCount()
            {
                return listOfViews.size();
            }

            @Override
            public void destroyItem(View container, int position, Object object)
            {
                ((ViewPager) container).removeView(listOfViews.get(position));
            }

            @Override
            public Object instantiateItem(View container, int position)
            {
                ((ViewPager) container).addView(listOfViews.get(position));
                return listOfViews.get(position);
            }
        };
        customViewPager.setAdapter(pagerAdapter0);

        SDKInitializer.initialize(this.getApplicationContext());//实例化百度地图

        //首页
        MainTabHomePage_only_instant_delivery_amendment.getInstance().onInit(viewPastHome, this);
        MainTabHomePage_only_instant_delivery_amendment.getInstance().onCreate();
        //订单
        MainTabFriendsPage.getInstance().onInit(viewOrder, this);
        MainTabFriendsPage.getInstance().onCreate();
        //消息
        MainTabMsgPage.getInstance().onInit(viewPastMsgs, this);
        MainTabMsgPage.getInstance().onCreate();

        //好友列表
        FriendListPage.getInstance().onInit(viewContactsList, this);
        FriendListPage.getInstance().onCreate();
        //我的
        MainTabMyPage.getInstance().onInit(viewMy, this);
        MainTabMyPage.getInstance().onCreate();


    }

    @Override
    protected void onDestroy()
    {
        super.onDestroy();
        mainBodyActivity_instance = null;

        Intent intentTemp = new Intent(MainBodyActivity.this, ChatService.class);
        stopService(intentTemp);
        intentTemp = new Intent(MainBodyActivity.this, FriendRequestService.class);
        stopService(intentTemp);
        try
        {
            unregisterReceiver(netStateReceiver);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }

        ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).cancelAll();
    }

    //每次横竖切屏，还有从其他界面返回的时候，都会调用这个函数。
    @Override
    public void onResume()
    {
        super.onResume();
        ConnectedApp.getInstance().setCurActivity(this);
    }

    //选择退回到home还是注销登录。
    @Override
    public void onBackPressed()
    {
        //		backToHome();
        logout();
    }

    //返回到按下home键的作用。
    public void backToHome()
    {
        Intent home = new Intent(Intent.ACTION_MAIN);
        home.addCategory(Intent.CATEGORY_HOME);
        startActivity(home);
    }

    public void logout()
    {
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
        alertDialogBuilder.setTitle(null);
        alertDialogBuilder
                .setMessage("确定要注销本次登录吗?")
                .setCancelable(false)
                .setPositiveButton("是", new DialogInterface.OnClickListener()
                {
                    public void onClick(DialogInterface dialog, int id)
                    {
                        MainBodyService.getInstance().saveOldMsgs();
                        MainBodyService.getInstance().saveTabMsgItems();
                        MainBodyService.getInstance().saveFrdNotifItems();
                        MainBodyService.getInstance().saveUnreadMsgAm();
                        FrdRequestNotifActivity.clearListOfNotif();
                        DbSaveOldMsg.getInstance().close();
                        MainBodyActivity.this.superOnBackPressed();
                    }
                }).setNegativeButton("取消", new DialogInterface.OnClickListener()
        {
            public void onClick(DialogInterface dialog, int id)
            {
                dialog.cancel();
            }
        });

        AlertDialog alertDialog = alertDialogBuilder.create();
        alertDialog.show();
    }

    public void superOnBackPressed()
    {
        super.onBackPressed();
        ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).cancelAll();
    }

    public class MainBodyOnClickListener implements View.OnClickListener
    {
        private int index = 0;

        public MainBodyOnClickListener(int i)
        {
            index = i;
        }

        @Override
        public void onClick(View v)
        {
            int page = mCurPageOnTab[index];
            gotoPage(index, page);
        }
    }

    ;

    /***
     * search friends
     ***/
    public void startSearch(SearchEntity sEnt0)
    {
        NetworkService.getInstance().sendUpload(GlobalMsgTypes.msgSearchPeople, sEnt0.toString());

        mMsg9Received = false;
        while (!mMsg9Received)
        {
        }

        gotoFriendSearchResult(mSearchedString);
    }

    public void onReceiveSearchList(String msg0)
    {
        mSearchedString = msg0;
        mMsg9Received = true;
    }

    /***
     * search friends
     ***/

    // 页面跳转；
    public void gotoPage(int tab, int page)
    {
        customViewPager.setCurrentItem(page, false); // 设置ViewPager当前页面
        mCurPage = page;
        mCurPageOnTab[tab] = page;
        setBottomImageview(tab);
    }

    // 底部菜单图片切换
    public void setBottomImageview(int tab)
    {
        switch (tab)
        {
            case mTabNumHome:
                tabHome_imageView.setImageDrawable(new IconicsDrawable(this, CommunityMaterial.Icon.cmd_home_map_marker).color(getResources().getColor(R.color.themeColor)).sizeDp(24).respectFontBounds(true));
                tabOrder_imageView.setImageDrawable(new IconicsDrawable(this, CommunityMaterial.Icon.cmd_clipboard_text).color(getResources().getColor(R.color.main_gray)).sizeDp(24).respectFontBounds(true));
                tabMsgs_imageView.setImageDrawable(new IconicsDrawable(this, CommunityMaterial.Icon.cmd_facebook_messenger).color(getResources().getColor(R.color.main_gray)).sizeDp(24).respectFontBounds(true));
                tabContacts_imageView.setImageDrawable(new IconicsDrawable(this, CommunityMaterial.Icon.cmd_account_multiple).color(getResources().getColor(R.color.main_gray)).sizeDp(24).respectFontBounds(true));
                tabMy_imageView.setImageDrawable(new IconicsDrawable(this, CommunityMaterial.Icon.cmd_account_circle).color(getResources().getColor(R.color.main_gray)).sizeDp(24).respectFontBounds(true));
                break;
            //订单
            case mTabOrder:
                tabHome_imageView.setImageDrawable(new IconicsDrawable(this, CommunityMaterial.Icon.cmd_home_map_marker).color(getResources().getColor(R.color.main_gray)).sizeDp(24).respectFontBounds(true));
                tabOrder_imageView.setImageDrawable(new IconicsDrawable(this, CommunityMaterial.Icon.cmd_clipboard_text).color(getResources().getColor(R.color.themeColor)).sizeDp(24).respectFontBounds(true));
                tabMsgs_imageView.setImageDrawable(new IconicsDrawable(this, CommunityMaterial.Icon.cmd_facebook_messenger).color(getResources().getColor(R.color.main_gray)).sizeDp(24).respectFontBounds(true));
                tabContacts_imageView.setImageDrawable(new IconicsDrawable(this, CommunityMaterial.Icon.cmd_account_multiple).color(getResources().getColor(R.color.main_gray)).sizeDp(24).respectFontBounds(true));
                tabMy_imageView.setImageDrawable(new IconicsDrawable(this, CommunityMaterial.Icon.cmd_account_circle).color(getResources().getColor(R.color.main_gray)).sizeDp(24).respectFontBounds(true));
                break;
            case mTabNumMsg:
                tabHome_imageView.setImageDrawable(new IconicsDrawable(this, CommunityMaterial.Icon.cmd_home_map_marker).color(getResources().getColor(R.color.main_gray)).sizeDp(24).respectFontBounds(true));
                tabOrder_imageView.setImageDrawable(new IconicsDrawable(this, CommunityMaterial.Icon.cmd_clipboard_text).color(getResources().getColor(R.color.main_gray)).sizeDp(24).respectFontBounds(true));
                tabMsgs_imageView.setImageDrawable(new IconicsDrawable(this, CommunityMaterial.Icon.cmd_facebook_messenger).color(getResources().getColor(R.color.themeColor)).sizeDp(24).respectFontBounds(true));
                tabContacts_imageView.setImageDrawable(new IconicsDrawable(this, CommunityMaterial.Icon.cmd_account_multiple).color(getResources().getColor(R.color.main_gray)).sizeDp(24).respectFontBounds(true));
                tabMy_imageView.setImageDrawable(new IconicsDrawable(this, CommunityMaterial.Icon.cmd_account_circle).color(getResources().getColor(R.color.main_gray)).sizeDp(24).respectFontBounds(true));
                break;
            case mTabNumContacts:
                tabHome_imageView.setImageDrawable(new IconicsDrawable(this, CommunityMaterial.Icon.cmd_home_map_marker).color(getResources().getColor(R.color.main_gray)).sizeDp(24).respectFontBounds(true));
                tabOrder_imageView.setImageDrawable(new IconicsDrawable(this, CommunityMaterial.Icon.cmd_clipboard_text).color(getResources().getColor(R.color.main_gray)).sizeDp(24).respectFontBounds(true));
                tabMsgs_imageView.setImageDrawable(new IconicsDrawable(this, CommunityMaterial.Icon.cmd_facebook_messenger).color(getResources().getColor(R.color.main_gray)).sizeDp(24).respectFontBounds(true));
                tabContacts_imageView.setImageDrawable(new IconicsDrawable(this, CommunityMaterial.Icon.cmd_account_multiple).color(getResources().getColor(R.color.themeColor)).sizeDp(24).respectFontBounds(true));
                tabMy_imageView.setImageDrawable(new IconicsDrawable(this, CommunityMaterial.Icon.cmd_account_circle).color(getResources().getColor(R.color.main_gray)).sizeDp(24).respectFontBounds(true));
                break;
            case mTabNumMy:
                tabHome_imageView.setImageDrawable(new IconicsDrawable(this, CommunityMaterial.Icon.cmd_home_map_marker).color(getResources().getColor(R.color.main_gray)).sizeDp(24).respectFontBounds(true));
                tabOrder_imageView.setImageDrawable(new IconicsDrawable(this, CommunityMaterial.Icon.cmd_clipboard_text).color(getResources().getColor(R.color.main_gray)).sizeDp(24).respectFontBounds(true));
                tabMsgs_imageView.setImageDrawable(new IconicsDrawable(this, CommunityMaterial.Icon.cmd_facebook_messenger).color(getResources().getColor(R.color.main_gray)).sizeDp(24).respectFontBounds(true));
                tabContacts_imageView.setImageDrawable(new IconicsDrawable(this, CommunityMaterial.Icon.cmd_account_multiple).color(getResources().getColor(R.color.main_gray)).sizeDp(24).respectFontBounds(true));
                tabMy_imageView.setImageDrawable(new IconicsDrawable(this, CommunityMaterial.Icon.cmd_account_circle).color(getResources().getColor(R.color.themeColor)).sizeDp(24).respectFontBounds(true));
                break;
            default:
                break;
        }
    }

    public void gotoChatActivity()
    {
        Intent intent0 = new Intent(MainBodyActivity.this, ChatActivity.class);
        startActivity(intent0.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT));
        overridePendingTransition(R.anim.my_slide_right_in, R.anim.my_slide_left_out);
    }

    public void gotoTabMsgFrdReqNotifActivity()
    {
        Intent intent0 = new Intent(MainBodyActivity.this, FrdRequestNotifActivity.class);
        startActivity(intent0.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT));
        overridePendingTransition(R.anim.my_slide_right_in, R.anim.my_slide_left_out);
    }

    public void gotoFriendSearchResult(String searchedString)
    {
        Intent intent0 = new Intent(MainBodyActivity.this, FriendSearchResultActivity.class);
        intent0.putExtra("searchResult", searchedString);
        startActivity(intent0.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT));
        overridePendingTransition(R.anim.my_slide_right_in, R.anim.my_slide_left_out);
    }

    public void gotoSearchBynameActivity()
    {
        Intent intent0 = new Intent(MainBodyActivity.this, SearchFriendByNameActivity.class);
        startActivity(intent0.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT));
        overridePendingTransition(R.anim.my_slide_right_in, R.anim.my_slide_left_out);
    }

    public void gotoAddFirendActivity()
    {
        Intent intent0 = new Intent(MainBodyActivity.this, AddFirendActivity.class);
        startActivity(intent0.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT));
        overridePendingTransition(R.anim.my_slide_right_in, R.anim.my_slide_left_out);
    }

    public void gotoMyLoginPageActivity()
    {
        Intent intent0 = new Intent(MainBodyActivity.this, MainActivity_login.class);
        startActivity(intent0.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT));
        overridePendingTransition(R.anim.my_slide_right_in, R.anim.my_slide_left_out);
    }

    //跳转我的资料页面。
    public void gotoMainMyDataPage()
    {

        UserInfo me = ConnectedApp.getInstance().getUserInfo();
        //验证是否登录。
        if (me == null)
        {
            Toast.makeText(MainBodyActivity.this, "请登录_20160524_192650", Toast.LENGTH_LONG).show();
            MainBodyActivity.getInstance().gotoMyLoginPageActivity();
            return;
        }

        Intent intent0 = new Intent(MainBodyActivity.this, MainMyDataPageActivity.class);
        startActivity(intent0.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT));
        overridePendingTransition(R.anim.my_slide_right_in, R.anim.my_slide_left_out);
    }

    //查看周边等待
    public void gotoTruck()
    {
        Intent intent = new Intent();
        intent.setClass(this, AroundCourierActivity.class);
        MainBodyActivity.this.startActivity(intent);
    }

    public void gotohaorenUseTest()
    {
        UserInfo me = ConnectedApp.getInstance().getUserInfo();
        //验证是否登录。
        /*if(me == null)
        {
            MainBodyActivity.getInstance().gotoMyLoginPageActivity();
            return;
        }*/
        Intent intent = new Intent();
        //		intent.setClass(this, AroundCourierActivity.class);
        intent.setClass(this, RadarDemo.class);
        MainBodyActivity.this.startActivity(intent);
    }

    //跳转页面。
    public void gotoSettingsActivity()
    {
        UserInfo me = ConnectedApp.getInstance().getUserInfo();
        //验证是否登录。
        if (me == null)
        {
            MainBodyActivity.getInstance().gotoMyLoginPageActivity();
            return;
        }

        Intent intent = new Intent();
//        intent.setClass(this, SettingsActivity.class);
//        intent.setClass(this, MainActivity.class);
        intent.setClass(this, com.tjian.fafa.user.module.settings.activity.SettingsActivity.class);

        int positionNow = DateUtilOfDemohi.acquireWeek();//课程表直接跳转到今天。
        intent.putExtra("POSITION", positionNow);
        MainBodyActivity.this.startActivity(intent);
    }


    public void gotoSearchByelseActivity()
    {
        Intent intent0 = new Intent(MainBodyActivity.this, SearchFriendByElseActivity.class);
        startActivity(intent0.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT));
        overridePendingTransition(R.anim.my_slide_right_in, R.anim.my_slide_left_out);
    }

    public void terminateAll()
    {
        ConnectedApp.getInstance().clearListActivity();
        ConnectedApp.getInstance().clearAll();

        InitData.closeInitData();
        FriendListInfo.closeFriendListInfo();
        ChatServiceData.closeChatServiceData();
    }

    //下一步
    public void homePageNextStepButtonOnClick(View view)
    {
        UserInfo me = ConnectedApp.getInstance().getUserInfo();
        //验证是否登录。
        if (me == null)
        {
            MainBodyActivity.getInstance().gotoMyLoginPageActivity();
            return;
        }
        Intent intent = new Intent();
        intent.setClass(this, BikeExpressageActivity.class);
        MainBodyActivity.this.startActivity(intent);
    }

    //跳转页面。
    public void gotoOsMainActivity_os()
    {
        UserInfo userInfo = ConnectedApp.getInstance().getUserInfo();
        //验证是否登录。
        /*if(me == null)
        {
            MainBodyActivity.getInstance().gotoMyLoginPageActivity();
            return;
        }*/

        Intent intent = new Intent();
        //Intent中直接加入标志Intent.FLAG_ACTIVITY_CLEAR_TOP，再次开启A时将会清除该进程空间的所有Activity。
        //intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        intent.setClass(getApplicationContext(), net.oschina.app.AppStart.class);

        MainBodyActivity.this.startActivity(intent);
    }

    //吕飞用测试
    public void haorenTestButtonOnClick(View view)
    {
        MainBodyActivity.getInstance().gotohaorenUseTest();
    }


    //吕飞用测试，不删除
    public void gotoRadarDemo()
    {
        UserInfo me = ConnectedApp.getInstance().getUserInfo();
        Intent intent = new Intent();
        intent.setClass(this, RadarDemo.class);
        MainBodyActivity.this.startActivity(intent);
    }

    //吕飞用测试，不删除
    public void gotoExtendFunction()
    {
        Intent intent = new Intent();
        intent.setClass(this, MainTabMyPageExtendActivity.class);
        MainBodyActivity.this.startActivity(intent);
    }


    //获取所有android6版本需要的权限
    public void obtainAllAndroid6Permissions()
    {
        String[] requestPermissionsArray = new String[]{Manifest.permission.READ_PHONE_STATE};
        //请求权限READ_PHONE_STATE
        ActivityCompat.requestPermissions(MainBodyActivity.this, requestPermissionsArray, PermissionConstant.READ_PHONE_STATE);
    }

    @Override
    public void onRequestPermissionsResult(int requestCode,
                                           String permissions[], int[] grantResults)
    {
        switch (requestCode)
        {
            case 1:
            {
                // If request is cancelled, the result arrays are empty.
                if (grantResults.length > 0
                        && grantResults[0] == PackageManager.PERMISSION_GRANTED)
                {
                    // permission was granted, yay! Do the
                    // contacts-related task you need to do.
                }
                else
                {

                    // permission denied, boo! Disable the
                    // functionality that depends on this permission.
                }
                return;
            }

            // other 'case' lines to check for other
            // permissions this app might request
        }
    }

    //跳转页面。
    public void goto_fafa_instant_delivery_activity()
    {
        Intent intent = new Intent();
        intent.setClass(getApplicationContext(), com.tjian.fafa.user.module.extend.Fafa_instant_delivery_activity.class);
        MainBodyActivity.this.startActivity(intent);
    }

}
